package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.TimeTableService;
import com.zrwl.poscloud.xo.vo.TimeTableVO;
/**
 * 课程表 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-05-08
 */
@RestController
@Api(value = "课程表相关接口", tags = {"课程表关联相关接口"})
@RequestMapping("/timeTable")
@Slf4j
public class TimeTableRestApi {
    @Autowired
    private TimeTableService timeTableService;
    @AuthorityVerify
    @ApiOperation(value = "获取课程表列表", notes = "获取课程表列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取课程表列表: {}", timeTableVO);
        return ResultUtil.successWithData(timeTableService.getPageList(timeTableVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取课程表列表", notes = "获取课程表列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取课程表列表: {}", timeTableVO);
        return ResultUtil.successWithData(timeTableService.getAllList(timeTableVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增课程表")    @ApiOperation(value = "新增课程表", notes = "新增课程表", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增课程表: {}", timeTableVO);
        return timeTableService.add(timeTableVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改课程表")    @ApiOperation(value = "修改课程表", notes = "修改课程表", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改课程表: {}", timeTableVO);
        return timeTableService.edit(timeTableVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除课程表")    @ApiOperation(value = "删除课程表", notes = "删除课程表", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除课程表: {}", timeTableVO);
        return timeTableService.delete(timeTableVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "停用课程表")    @ApiOperation(value = "停用课程表", notes = "停用课程表", response = String.class)
    @PostMapping("/editStop")
    public String editStop(@Validated({Update.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        if (timeTableVO.getTimeTableVOList().size()==0){
            ThrowableUtils.checkParamArgument(result);
        }
        log.info("停用课程表: {}", timeTableVO);
        return timeTableService.editStop(timeTableVO);
    }
}
